import { Controller,Headers, Get, Post, Body, Put,Query, Param, Delete } from '@nestjs/common';
import { TagService } from './tag.service';
import { ApiTags } from '@nestjs/swagger';
import {TagDto} from './dto/tag.dto'
import { isNoAuth } from 'src/utils/decorator/jwt.decorator';
@ApiTags('标签管理')
@Controller('tag')
@isNoAuth()
export class TagController {
  constructor(private readonly tagService: TagService) {}

  @Post("add")
  create(@Headers() header,@Body() tagDto: TagDto) {
    const dto = {...tagDto, userId: header.userid }
    return this.tagService.create(dto);
  }

  @Get("all")
  findAll(@Headers() header):Promise<any> {
    return this.tagService.findAll(header.userid);
  }

  @Get("list")
  list(@Headers() header,@Query() query):Promise<any> {
    return this.tagService.list(query.page,query.pageSize,header.userid);
  }

  @Get("search")
  async findOne(@Query() query):Promise<TagDto[]> {
    return  await this.tagService.findOne(query.name,query.id);
  }
  @Put('update/:id')
  update(@Param() param, @Body() tagDto: TagDto) {
    return this.tagService.update(param.id, tagDto);
  }

  @Delete('del')
  remove(@Query() query):Promise<string> {
    return this.tagService.remove(query.id);
  }
}
